<template>
  <div>
    <el-form :inline="true" :model="queryForm" @keyup.enter.native="getDataList('reset')">
      <el-form-item label="订单号">
        <el-input v-model="queryForm.order_code" maxlength="30" placeholder="订单号" clearable></el-input>
      </el-form-item>
      <el-form-item label="店铺类型">
        <el-select v-model="queryForm.platform_shop" placeholder="店铺类型" clearable>
          <el-option label="第三方" :value="0"></el-option>
          <el-option label="自营店" :value="1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="更新时间">
        <el-date-picker v-model="timeArr" value-format="yyyy-MM-dd HH:mm:ss" type="datetimerange" @change="timeChange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" clearable>
        </el-date-picker>
      </el-form-item>
      <el-form-item label="来源">
        <el-select v-model="queryForm.area_feature" placeholder="来源">
          <el-option label="全部" :value="-1"></el-option>
          <el-option label="普通商品" :value="0"></el-option>
          <el-option label="服务体系礼包" :value="1"></el-option>
          <el-option label="新人福利区" :value="2"></el-option>
          <el-option label="公益申领" :value="3"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="getDataList('reset')">查询</el-button>
        <el-button icon="el-icon-refresh-left" @click="reset">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table :data="dataList" border v-loading="dataListLoading" style="width: 100%;">
      <el-table-column align="center" label="序号" width="60">
        <template slot-scope="scope">
          <span>{{(queryForm.page - 1) * queryForm.limit + scope.$index + 1}}</span>
        </template>
      </el-table-column>
      <el-table-column prop="orderCode" header-align="center" align="center" label="订单号">
      </el-table-column>
      <el-table-column prop="platformShop" header-align="center" align="center" label="店铺类型">
        <template slot-scope="{row}">
          <div v-if="!row.platformShop">第三方</div>
          <div v-else>自营店</div>
        </template>
      </el-table-column>
      <el-table-column prop="shopName" header-align="center" align="center" label="店铺名称">
      </el-table-column>
      <el-table-column prop="childOrderFaceValue" header-align="center" align="center" label="订单金额">
      </el-table-column>
      <el-table-column prop="donationValue" header-align="center" align="center" label="原捐款金额">
      </el-table-column>
      <el-table-column prop="existsRefund" header-align="center" align="center" label="是否存在退款">
        <template slot-scope="{row}">
          <div>
            <el-tag type="success" v-if="row.existsRefund">是</el-tag>
            <el-tag type="danger" v-else>否</el-tag>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="refundDeduct" header-align="center" align="center" label="退款影响值">
      </el-table-column>
      <el-table-column prop="ableGains" header-align="center" align="center" label="实际捐款金额">
      </el-table-column>
      <el-table-column prop="areaFeature" header-align="center" align="center" label="来源">
        <template slot-scope="{row}">
          <div v-if="row.areaFeature==0">普通商品</div>
          <div v-if="row.areaFeature==1">服务体系礼包</div>
          <div v-if="row.areaFeature==2">新人福利区</div>
          <div v-if="row.areaFeature==3">公益申领</div>
        </template>
      </el-table-column>
      <el-table-column prop="createTime" header-align="center" align="center" label="更新时间" width="180">
      </el-table-column>
    </el-table>

    <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="queryForm.page" :page-sizes="[10, 20, 50, 100]" :page-size="queryForm.limit" :total="total" layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
  </div>
</template>

<script>
import serviceApi from '@/api/serviceApi.js'
export default {
  data () {
    return {
      queryForm: {
        limit: 10,
        page: 1,
        area_feature: -1
      },
      total: 0,
      dataList: [],
      dataListLoading: false,
      timeArr: []
    }
  },
  created () {
    this.getDataList()
  },
  methods: {
    timeChange (e) {
      if (e) {
        this.queryForm.start_time = e[0];
        this.queryForm.end_time = e[1];
      } else {
        this.queryForm.start_time = null;
        this.queryForm.end_time = null
      }
    },
    getDataList (reset) {
      if (reset) this.queryForm.page = 1;
      for (let v in this.queryForm) {
        if (!this.queryForm[v] && this.queryForm[v] !== 0) {
          delete this.queryForm[v]
        }
      }
      this.dataListLoading = true;
      serviceApi.shopordergainsdonationList(this.queryForm).then(res => {
        if (res && res.data.code == 200) {
          this.dataList = res.data.page.list;
          this.total = res.data.page.totalCount;
        }
        this.dataListLoading = false;
      })
    },
    reset () {
      this.queryForm = {
        limit: 10,
        page: 1,
        area_feature: -1
      }
      this.timeArr = [];
      this.getDataList()
    },
    // 每页数
    sizeChangeHandle (val) {
      this.queryForm.limit = val
      this.getDataList()
    },
    // 当前页
    currentChangeHandle (val) {
      this.queryForm.page = val
      this.getDataList()
    },
  }
}
</script>

<style lang="scss">
</style>